// 最顶层的一些函数，公共的
library Base initializer init requires YDWETimerSystem

    // 获取坐标的高度
    function getZByXY takes real x, real y returns real
        local location p = Location(x, y)
        local real v
        set v = GetLocationZ(p)
        call RemoveLocation(p)
        set p = null
        return v
    endfunction

    // i表示样式，1红色（致命一击），2蓝色（会心），3绿色（卓越一击），4橙色（无视一击），0表示普通伤害样式（白色）  6金币  7木材
    // shv表示伤害显示的数字
    function showSHWZ takes integer uid, integer shv, integer i, real x, real y returns nothing
        
        local string shvStr = I2S(shv)
        local integer lt = StringLength(shvStr)
        local integer loopi
        local string sz
        local string szType
        local effect ect
        local string prefix = ""
        // 偏移量（增加高度
        local real offset = 0.0

        set y = y + 50.0
        // 白色的
        if (i == 0) then
            set szType = "pg_"
            set offset = 120.0
        // 红色的
        elseif (i == 1) then
            set szType = "baoji_"
            set offset = 50.0
            // 显示前面的符号
            // if (Player(uid) == GetLocalPlayer()) then
            //     set prefix = "baoji_bs.mdx"
            // endif
            // set ect = AddSpecialEffect(  prefix, x-I2R(15*lt)-30, y)
            // call EXSetEffectSize( ect, 1.0 )
            // call DestroyEffect ( ect )
        elseif (i == 2) then
            set szType = "lanse_"
            set offset = 20.0
            // 显示前面的符号
            // if (Player(uid) == GetLocalPlayer()) then
            //     set prefix = "lanse_bs.mdx"
            // endif
            // set ect = AddSpecialEffect(  prefix, x-I2R(15*lt)-30, y)
            // call EXSetEffectSize( ect, 1.0 )
            // call DestroyEffect ( ect )
        elseif (i == 3) then
            set szType = "huifu_"
            set offset = 60.0
            // 显示前面的符号
            // if (Player(uid) == GetLocalPlayer()) then
            //     set prefix = "huifu_bs.mdx"
            // endif
            // call DestroyEffect ( AddSpecialEffect(  prefix, x-I2R(15*lt)-30, y) )
        // 黄色，闪电伤害
        elseif (i == 4) then
            set szType = "baoji2_"
            set offset = 100.0
        // 金币显示
        elseif (i == 6) then
            set x = x + 200.0
            set y = y + 80.0
            set szType = "jinbi_"
            // 显示前面的符号
            if (Player(uid) == GetLocalPlayer()) then
                set prefix = "jinbi_jb.mdx"
            endif
            set ect = AddSpecialEffect(  prefix, x-I2R(30*lt)-50, y)
            call EXSetEffectSize( ect, 1.2 )
            call DestroyEffect ( ect )
        // 木材显示
        elseif (i == 7) then
            set x = x + 200.0
            set y = y + 80.0
            set szType = "mucai_"
            // 显示前面的符号
            if (Player(uid) == GetLocalPlayer()) then
                set prefix = "mucai_mt.mdx"
            endif
            set ect = AddSpecialEffect(  prefix, x-I2R(30*lt)-50, y)
            call EXSetEffectSize( ect, 1.2 )
            call DestroyEffect ( ect )
        endif

        // 这里是为了伤害字体只有自己能看见
        if (Player(uid) != GetLocalPlayer()) then
            set szType = ""
        endif
        // 大于10000省略(万字)
        // if ((shv >= 100000) and (i != 6) and (i != 7)) then
        //     set shvStr = I2S(shv/10000)
        //     set lt = StringLength(shvStr)
        //     set ect = AddSpecialEffect(  (szType+"wan.mdx"), x+ 10.0 +I2R(lt*25), y)
        //     // 这个注释的左移了
        //     // set ect = AddSpecialEffect(  (szType+"wan.mdx"), x-I2R(15*lt)+I2R(lt*25), y)

        //     if offset > 0.0 then
        //         call EXSetEffectZ( ect, getZByXY(x, y) + offset )
        //     endif
        //     call EXSetEffectSize( ect, 1.0 )
        //     call DestroyEffect ( ect )
        // endif
        // 数字显示

        // 金币和木材的效果放大一点
        if ((i == 6) or (i == 7)) then
            set loopi = 0
            loop
            exitwhen loopi >= lt
            
            set sz = SubString(shvStr, loopi,loopi+1)
            set ect = AddSpecialEffect(  (szType+sz+".mdx"), x-I2R(30*lt)+I2R(loopi*35), y)
            //call EXSetEffectZ( ect, -2.50 )
            call EXSetEffectSize( ect, 1.2 )
            call DestroyEffect ( ect )

            set loopi = loopi + 1
            endloop
        else
            set loopi = 0
            loop
            exitwhen loopi >= lt
            
            set sz = SubString(shvStr, loopi,loopi+1)
            set ect = AddSpecialEffect(  (szType+sz+".mdx"), x+I2R(loopi*28), y)
            call EXSetEffectSize( ect, 1.5 )
            // 这个注释的左移了
            // set ect = AddSpecialEffect(  (szType+sz+".mdx"), x-I2R(15*lt)+I2R(loopi*25), y)
            if offset > 0.0 then
                call EXSetEffectZ( ect, getZByXY(x, y) + offset )
            endif
            call EXSetEffectSize( ect, 1.5 )
            call DestroyEffect ( ect )

            set loopi = loopi + 1
            endloop
        endif

        set ect = null
        set sz = null
        set szType = null
        set shvStr = null
        set prefix = null
    endfunction

    private function init takes nothing returns nothing
        
    endfunction
endlibrary

